package com.ztc.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.ztc.bean.LibraryModel;

/**
 * @类名：LibraryDao.java
 * @作者：李晓平
 * @时间：2018年7月25日 下午3:08:28
 * @描述：行业库Dao
 */
@Mapper
public interface LibraryDao {

	/**
	 * 查询我的行业库
	 * @param library
	 * @return
	 */
	@Select("<script>"
			+ "select id,title from tab_library"
			+ " where 1=1"
			+ "<if test='library.categoryId!=null and library.categoryId!=\"\"'>"
			+ " and (categoryId=#{library.categoryId} or categoryId=0)"
			+ "</if>"
			+ "<if test='library.authId!=null and library.authId!=\"\"'>"
			+ " and authId=#{library.authId}"
			+ "</if>"
			+ "<if test='library.title!=null and library.title!=\"\"'>"
			+ " and title like '%${library.title}%'"
			+ "</if>"
			+ "<if test='library.content!=null and library.content!=\"\"'>"
			+ " and content=#{library.content}"
			+ "</if>"
			+ "<if test='library.enterpriseId!=null and library.enterpriseId!=\"\"'>"
			+ " and enterpriseId=#{library.enterpriseId}"
			+ "</if>"
			+ " order by id"
			+ "</script>")
	public List<LibraryModel> queryLibraryList(@Param("library") LibraryModel library);
	
	/**
	 * 查询单个行业库明细
	 * @param id
	 * @return
	 */
	@Select("select * from tab_library where id=#{id}")
	public LibraryModel queryOneLibrary(@Param("id") int id);

	/**
	 * 添加行业库
	 * @param library
	 * @return
	 */
	@Insert("insert into tab_library(authId,projectId,categoryId,userId,title,content,enterpriseId)"
			+ " values (#{library.authId},#{library.projectId},#{library.categoryId},#{library.userId},#{library.title},#{library.content},#{library.enterpriseId})")
	public int addLibrary(@Param("library") LibraryModel library);
	
	/**
	 * 删除行业库
	 * @param id
	 * @return
	 */
	@Delete("delete from tab_library where id=#{id}")
	public int deleteLibrary(@Param("id") int id);
}
